package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/10/1 10:44
 * @apiNote
 */

public class Test00279NumSquares {
    public static void main(String[] args) {
        int n = 12;
        System.out.println(numSquares(n));
    }
    public static  int numSquares(int n) {
        int[] dp = new int[n+1];
        for(int i = 1;i<=n;i++){
            int min = Integer.MAX_VALUE;
            for(int j = 1 ; j*j <= i;j++){
                min = Math.min(min,dp[i-j*j]);
            }
            dp[i] = min +1;
        }
        return dp[n];
    }
}
